from rest_framework import permissions


class IsActiveUser(permissions.IsAuthenticated):
    """管理员权限"""
    def has_permission(self, request, view):
        return bool(
            super().has_permission(request, view) and 
            request.user.is_active
        )
    
class DjangoModelPermissions(permissions.DjangoModelPermissions):
    """使用django的权限验证
    """
    perms_map = {
        'GET': ['%(app_label)s.view_%(model_name)s'],
        'OPTIONS': ['%(app_label)s.view_%(model_name)s'],
        'HEAD': ['%(app_label)s.view_%(model_name)s'],
        'POST': ['%(app_label)s.add_%(model_name)s'],
        'PUT': ['%(app_label)s.change_%(model_name)s'],
        'PATCH': ['%(app_label)s.change_%(model_name)s'],
        'DELETE': ['%(app_label)s.delete_%(model_name)s'],
    }


# class MenusPermission(IsActiveUser):

#     def has_permission(self, request, view):
#         is_permission = super().has_permission(request, view)
#         # 获取当前用户的所有分组
#         groups = request.user.groups.all()


#         return is_permission
